package com.ljx.api.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @类名: MyMetaObjectHandler
 * @描述:
 * @日期: 2020-09-03 16:10
 * @作者: 刘纪譞
 * @版本: 1.0.0
 * <p>
 * since JDK 1.8
 **/

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        log.info("-----"+ JSONArray.toJSONString(metaObject));
        this.setInsertFieldValByName("createDate", LocalDateTime.now(ZoneId.of("+16:00")), metaObject);
        //@since 快照：3.0.7.2-SNAPSHOT， @since 正式版暂未发布3.0.7
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateDate", LocalDateTime.now(), metaObject);
    }
}
